/**
 * @file    parallel_com.h
 * @brief   并机协议-串口
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-04-21
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-21 <td>1.0.1     <td>name     <td>首次创建
 * </table>
 */

#ifndef __PARALLEL_COM_H_
#define __PARALLEL_COM_H_

/* file includes -------------------------------------------------------------*/
#include "mcu_type.h"
#include "parallel.h"
/* cplusplus -----------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

/* macro/define/typedef ------------------------------------------------------*/
enum
{
    BST_CMD_TRUE = 0x01,
    BST_ERR_CRC ,
    BST_ERR_LEN , 
    BST_ERR_DEV_ADDR , 
    BST_ERR_CMD , 
    BST_ERR_REG_ADDR ,
};
/* 透传缓冲区大小 */
#define SERIANET_BUFF_SIZE      (540)  
#define BROADCASE_ADDR          (0xFF)
/* 透传数据类型 */
typedef struct 
{
	uint8_t recv_flag;
	uint8_t send_flag;
	uint8_t dev_addr;
	uint8_t cmd;
	uint16_t timeout_cnt;
    uint16_t tx_num;
    uint8_t tx_buf[SERIANET_BUFF_SIZE];
}serialnet_data_type;

/* @brief */

/* variables -----------------------------------------------------------------*/
extern master_data_type master_data_reg;
/*******************************************************************************
 * public API List
 ******************************************************************************/
uint8_t parallel_com_recv_deal(uint8_t *rx_buf , uint16_t rx_len ,uint8_t *tx_buf , uint16_t *tx_len , uint8_t addr_flag);
uint8_t parallel_com_master_deal(uint16_t cycle , uint8_t *tx_buf ,uint16_t *tx_len);
void parallel_com_master_broadcast_sleep(uint8_t com_id);
uint8_t parallel_com_read_slave_data(uint8_t *rx_buf , uint16_t rx_len);
uint8_t parallel_bst_serianet(uint8_t *rx_buf , uint16_t rx_len , serialnet_data_type *serianet_data);
uint8_t parallel_bst_analysis_recv(uint8_t *rx_buf , uint16_t rx_len, serialnet_data_type serianet_data);
uint8_t parallel_com_auto_addr(uint8_t com_id , uint16_t cycle);
uint8_t parallel_com_serialnet(uint8_t *rx_buf , uint16_t rx_len , serialnet_data_type *serianet_data);
void com_report_total_msg(uint8_t *tx_buf , uint16_t *tx_len);

#ifdef __cplusplus
}
#endif

#endif  /* #ifndef __PARALLEL_COM_H_ */
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/
